<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
  <th:block th:include="include :: header('财务运单列表')" />
  <th:block th:include="include :: bootstrap-select-css" />
</head>
<body class="gray-bg">
<div class="container-div">
  <div class="row">
    <div class="col-sm-10 search-collapse">
      <form id="formId">
        <div class="select-list">
          <ul>
            <li>
              <label>驾驶员：</label>
              <input type="text" id="transporter" name="transporter"/>
            </li>
            <li>
              <label>驾驶员电话：</label>
              <input type="number" id="transporterPhone" name="transporterPhone"/>
            </li>
            <li>
              <label>车牌号：</label>
              <input type="text" id="plateNumber" name="plateNumber"/>
            </li>
            <li class="select-time">
              <label>操作时间：</label>
              <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginTime]"/>
              <span>-</span>
              <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endTime]"/>
            </li>
            <li>
              <a class="btn btn-primary btn-rounded btn-sm" onclick="searchPre()"><i class="fa fa-search"></i>&nbsp;搜索</a>
              <a class="btn btn-warning btn-rounded btn-sm" onclick="resetPre()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
            </li>
          </ul>
        </div>
      </form>
    </div>

    <div class="btn-group-sm" id="toolbar" role="group">
      <a id="hidDiv" class="btn btn-success" onclick="$.operate.settlementAll()" shiro:hasPermission="system:order:edit">
        <i class="fa fa-plus"></i> 批量结算
      </a>
      <!--      <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:finance:export">-->
      <!--        <i class="fa fa-download"></i> 导出-->
      <!--      </a>-->

    </div>

    <div class="col-sm-12 select-table table-striped">
      <table id="bootstrap-table"></table>
    </div>
  </div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: bootstrap-select-js" />
<script th:inline="javascript">
  document.getElementById('hidDiv').style.display='none';

  var editFlag = [[${@permission.hasPermi('system:finance:edit')}]];
  var datasPay = [[${@dict.getType('pay_type')}]];
  var datasType = [[${@dict.getType('order_type')}]];
  var detailFlag = [[${@permission.hasPermi('system:finance:detail')}]];
  var completionFlag = [[${@permission.hasPermi('system:finance:completion')}]];
  var refundFlag = [[${@permission.hasPermi('system:finance:refund')}]];

  var prefix = ctx + "system/finance";


  $(function() {
    var options = {
      url: prefix + "/list",
      refundUrl: prefix + "/refund",
      completionUrl: prefix + "/completion",
      updateUrl: prefix + "/edit/{id}",
      exportUrl: prefix + "/export",
      detailUrl: prefix + "/detail/{id}",
      settlementUrl: prefix + "/settlement",
      detailedUrl : prefix + "/detailed/{id}",
      salesmanUrl: prefix + "/salesman/{id}",
      modalName: "财务运单",
      columns: [{
        checkbox: true
      },
        {
          field: 'id',
          title: '主键',
          visible: false
        },
        {
          field: 'orderId',
          title: '主键',
          visible: false
        },
        {
          field: 'createUser',
          title: '建单人'
        },
        {
          field: 'vehicleInspector',
          title: '提验人'
        },
        {
          field: 'inspectionFee',
          title: '提验费'
        },
        {
          field: 'agencyFee',
          title: '中介费'
        },
        {
          field: 'userName',
          title: '业务员'
        },
        {
          field: 'vehicleModel',
          title: '车型'
        },
        {
          field: 'vin',
          title: '车架号'
        },
        {
          field: 'origin',
          title: '起始地'
        },
        {
          field: 'dest',
          title: '目的地'
        },
        {
          field: 'transporter',
          title: '驾驶员',
          visible: false
        },
        {
          field: 'transporterPhone',
          title: '驾驶员电话',
          visible: false
        },
        {
          field: 'plateNumber',
          title: '车牌号',
          visible: false
        },
        {
          field: 'amount',
          title: '到收',
          visible: false
        },
        {
          field: 'transferFee',
          title: '中转费',
          visible: false
        },
        {
          field: 'owes',
          title: '欠/返',
          visible: false
        },
        {
          field: 'refund',
          title: '欠/返状态',
          visible: false,
          formatter: function (value, row, index) {
            if (row.owes > 0 && !row.refund) {
              return '<span class="badge badge-danger">未收到返款</span>';
            } else if (row.owes > 0 && row.refund) {
              return '<span class="badge badge-primary">已收到返款</span>';
            } else if (row.owes < 0 && !row.refund) {
              return '<span class="badge badge-success">未支付运费</span>';
            } else if (row.owes < 0 && row.refund) {
              return '<span class="badge badge-primary">已支付运费</span>';
            }
          }
        },
        {
          field: 'payType',
          title: '支付方式',
          align: 'center',
          formatter: function(value, row, index) {
            return $.table.selectDictLabel(datasPay, value);
          }
        },
        {
          field: 'freightAmount',
          title: '运费金额'
        },
        {
          field: 'paidAmount',
          title: '已付金额'
        },
        {
          field: 'orderType',
          title: '订单状态',
          align: 'center',
          formatter: function(value, row, index) {
            return $.table.selectDictLabel(datasType, value);
          }
        },
        {
          field: 'notGive',
          title: '欠反',
          align: 'center',
          formatter: function (value, row, index) {
            if (row.notGive) {
              return '<span class="badge badge-danger">有欠反</span>';
            } else {
              return '<span class="badge badge-primary">无</span>';
            }
          }
        },
        {
          field: 'notPay',
          title: '欠付',
          align: 'center',
          formatter: function (value, row, index) {
            if (row.notPay) {
              return '<span class="badge badge-danger">有欠付</span>';
            } else {
              return '<span class="badge badge-primary">无</span>';
            }
          }
        },
        {
          field: 'createTime',
          title: '建单时间'
        },
        {
          title: '操作',
          align: 'center',
          formatter: function(value, row, index) {
            var actions = [];

            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editFull(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
            if(row.orderTransferId != null && !row.refund){
              actions.push('<a class="btn btn-success btn-xs' + refundFlag + '" href="javascript:void(0)" onclick="$.operate.settlement(\'' + row.orderTransferId + '\')">结算</a>');
            }else if(row.refund){
              actions.push('<a class="btn btn-info btn-xs" >已结算</a>');
            }
            if(row.orderTransferId == null && row.orderType < 6){
              actions.push('<a class="btn btn-success btn-xs' + completionFlag + '" href="javascript:void(0)" onclick="$.operate.completion(\'' + row.id + '\')">是否完结</a>');
            }
            if(row.orderTransferId != null){
              actions.push('<a class="btn btn-warning btn-xs ' + detailFlag + '" href="javascript:void(0)" onclick="$.operate.detailTab(\'' + row.orderId + '\')"><i class="fa fa-search"></i>详情</a>');
            }else{
              actions.push('<a class="btn btn-warning btn-xs ' + detailFlag + '" href="javascript:void(0)" onclick="$.operate.detailTab(\'' + row.id + '\')"><i class="fa fa-search"></i>详情</a>');
            }
            return actions.join('');
          }
        }]
    };
    $.table.init(options);
  });

  function searchPre() {
    var transporter = $("#transporter").val();
    var transporterPhone = $("#transporterPhone").val();
    var plateNumber = $("#plateNumber").val();
    if(transporter.length > 0 || transporterPhone.length > 0 || plateNumber.length > 0){
      $.table.showColumn("transporter");
      $.table.showColumn("transporterPhone");
      $.table.showColumn("plateNumber");
      $.table.showColumn("owes");
      $.table.showColumn("amount");
      $.table.showColumn("transferFee");
      $.table.showColumn("refund");
      document.getElementById('hidDiv').style.display='block';

      $.table.hideColumn("profit");
      $.table.hideColumn("commission");
      $.table.hideColumn("notGive");
      $.table.hideColumn("notPay");
    }else {
      $.table.hideColumn("transporter");
      $.table.hideColumn("transporterPhone");
      $.table.hideColumn("plateNumber");
      $.table.hideColumn("owes");
      $.table.hideColumn("amount");
      $.table.hideColumn("transferFee");
      $.table.hideColumn("refund");
      document.getElementById('hidDiv').style.display='none';
      $.table.showColumn("profit");
      $.table.showColumn("commission");
      $.table.showColumn("notGive");
      $.table.showColumn("notPay");
    }
    $.table.search();
  }

  function resetPre() {
    resetDate();
    $("#formId")[0].reset();
    $.table.hideColumn("transporter");
    $.table.hideColumn("transporterPhone");
    $.table.hideColumn("plateNumber");
    $.table.hideColumn("owes");
    $.table.hideColumn("amount");
    $.table.hideColumn("transferFee");
    $.table.hideColumn("refund");
    document.getElementById('hidDiv').style.display='none';

    $.table.showColumn("profit");
    $.table.showColumn("commission");
    $.table.showColumn("notGive");
    $.table.showColumn("notPay");
    $.table.search();
  }
</script>
</body>
</html>